package srzy.common

import scala.util.parsing.combinator._
import scala.util.matching.Regex
import sun.font.TrueTypeFont

object CdrLogParser extends RegexParsers {

  def ` ` = """[ ]+""".r

  def str: Parser[String] = """[^;:]*""".r ^^ { _.toString }
  def int: Parser[Int] = """[0-9]*""".r ^^ { _.toInt }

  def group1: Parser[(String, String)] = str ~ ":" ~ str ^^
    { case s1 ~ _ ~ s2 => (s1, s2) }
  def group2: Parser[Map[String, String]] = repsep(group1, ";") ^^
    { case g => g.toMap }

  //  def group3: Parser[Map[String, Map[String, (String, List[Int])]]] = repsep(group2, "^") ^^
  //    { case s => s.toMap }

  def parse(text: String): Map[String, String] = {
    parseAll(group2, text) match {
      case Success(r, _) => r
      case Failure(msg, _) => throw new Exception("YAML Parser failure :" + msg)
      case Error(msg, _) => throw new Exception("YAML Parser error :" + msg)
    }
  }

}